package net.sdd.school.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.sdd.school.entity.Trainer;
import net.sdd.school.mapper.TrainerMapper;
import net.sdd.school.service.ITrainerService;
import net.sdd.school.vo.query.TrainerQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * <p>
 * 培训师 服务实现类
 * </p>
 *
 * @author Jet
 * @since 2022-08-16
 */
@Service
public class TrainerServiceImpl extends ServiceImpl<TrainerMapper, Trainer> implements ITrainerService {

    @Override
    public IPage<Trainer> findByPage(Integer current, Integer size, TrainerQueryVo queryVo) {
        // 创建条件对象
        QueryWrapper<Trainer> wrapper = new QueryWrapper<>();
        if (!Objects.isNull(queryVo)) {
            // 构造条件
            if (!StringUtils.isEmpty(queryVo.getName())) {
                wrapper.like("name",queryVo.getName());
            }
            if (queryVo.getLevel() != null) {
                wrapper.eq("level",queryVo.getLevel());
            }
            if (queryVo.getStart() != null) {
                wrapper.gt("create_time",queryVo.getStart());
            }
            if (queryVo.getEnd() != null) {
                wrapper.lt("create_time",queryVo.getEnd());
            }
        }
        // 分页条件查询
        Page<Trainer> page = this.page(new Page<>(current, size),wrapper);
        return page;
    }
}
